<?php

namespace App\Http\Controllers\Api\V1;

use Carbon\Carbon;
use App\Models\Brand;
use App\Models\BrandModel;
use Illuminate\Support\Facades\DB;
use App\Http\Controllers\Api\V1\Resources\BrandResource;
use App\Http\Controllers\Api\V1\Resources\BrandModelResource;

class BrandsController extends Controller
{
	public function index()
	{
		
		$screens = Brand::query()
			->where('is_shown',true)
			->orderBy("order")
			->take(4)
			->get();
		
		return BrandResource::collection($screens);
	}

	public function hot()
	{
		
		$screens = Brand::query()
			->where('is_hot',true)
			->orderBy("order")
			->take(4)
			->get();
		
		return BrandResource::collection($screens);
	}

	public function all()
	{
		
		$screens = Brand::query()
			->where('is_shown',true)
			->orderBy(DB::raw('CONVERT( name USING gbk ) COLLATE gbk_chinese_ci')) 
			->get();
		
		return BrandResource::collection($screens);
	}

	public function brandModel()
	{
		

		$brandId = request('brand_id');

		if(!$brandId){
			return []; 

		}
		$models = BrandModel::query()->where("brand_id",$brandId)->orderBy('name', 'asc')->where("is_hidden",0)->get();
		
		return BrandModelResource::collection($models);
	}

	
}
